<!DOCTYPE html>
<html>
<head>
	<title>排列组合</title>
</head>
<body>

<script>
function sum (num, n) {
    let total = 1;
    while(n) {
        total = total * (num - n + 1);
        n--;
    }

    return total;
}

function jumpFloor(number)
{
    // write code here
    let total = 0;
    // 最多能放的2的个数
    let twoMax = parseInt(number / 2);
    // 0个2,使用所有的1
    total += 1;

    while(twoMax) {
        let posNum = number - twoMax;//有多少个位置可以放2
        let sign = sum(posNum, twoMax) / sum(twoMax, twoMax);// 梯乘,得到2的不同排列的组合次数,因为都是放2,所以需要除于2的个数的梯乘
        console.log('twoMax:', twoMax, 'posNum:', posNum, 'sign:', sign);
        total += sign;
        twoMax--;
    }
    return total;
}

console.log(jumpFloor(5));
//2--[1,1],         [2]
//3--[1,1,1],       [2,1],[1,2]
//4--[1,1,1,1],     [2,1,1],[1,2,1],[1,1,2],                            [2,2]
//5--[1,1,1,1,1],   [2,1,1,1],[1,2,1,1],[1,1,2,1],[1,1,1,2]             [2,2,1],[2,1,2],[1,2,2]
//6--[1,1,1,1,1,1], [2,1,1,1,1],[1,2,1,1,1],[1,1,2,1,1],[1,1,1,2,1],[1,1,1,2,1]
//6--0--1
//6--1--5
//6--2--6
//6--3--1

</script>
</body>
</html>